Imports System.Windows.Forms

Public Class frmCopyTables

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub frmCopyTables_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        With Me.cboTableType
            .Items.Add("Working & Master Tables")
            .Items.Add("Support Tables")
            If Project.DB.DatabaseType <> clsDB.enumDBType.Paradox Then .Items.Add("All Tables")
            .SelectedIndex = 0
        End With
        Me.cboProject.Items.Clear()
        Me.cboProject.Items.AddRange(IniFile.GetProjectNames.ToArray(GetType(String)))
        Me.cboProject.Text = IniFile.GetKey(clsWRDBIniFile.enumSection.Application, clsWRDBIniFile.enumKey.AppLastProjectName)
        IniFile.Save()
    End Sub

    Private Sub cboTableType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboTableType.SelectionChangeCommitted
        FillTableList()
    End Sub

    Private Sub cboProject_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboProject.SelectedIndexChanged
        FillTableList()
    End Sub

    Private Sub FillTableList()
        Try
            Me.lstTables.Items.Clear()
            If Not MainWRDB.DataProviderAvailable(Me.cboProject.Text) Then Exit Sub
            Try
                OtherProject = New clsProject(Me.cboProject.Text)
            Catch ex As DbSqlException
                WarningMsg(ex.Message)
                Exit Sub
            End Try
            If cboTableType.Text.StartsWith("Support") Then
                OtherProject.ResetPDox(clsProject.enumTableTypes.Stations)
            Else
                OtherProject.ResetPDox(clsProject.enumTableTypes.Working)
            End If
            For Each s As String In OtherProject.DB.GetTableList()
                Dim TblType As clsProject.enumTableTypes = OtherProject.GetTableType(s)
                If cboTableType.Text.StartsWith("All") OrElse _
                    (cboTableType.Text.StartsWith("Working") And (TblType = clsProject.enumTableTypes.Working Or TblType = clsProject.enumTableTypes.Master)) OrElse _
                    (cboTableType.Text.StartsWith("Support") And TblType >= clsProject.enumTableTypes.Stations) Then
                    Me.lstTables.Items.Add(s)
                End If
            Next
        Catch ex As Exception
            ErrorMsg(, ex)
        Finally
            OtherProject.DB.Connection.Close()
            OtherProject.DB.Dispose()
            OtherProject = Nothing
        End Try
    End Sub

    Private Sub lstTables_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstTables.DoubleClick
        btnOK.PerformClick()
    End Sub

End Class
